home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 98 / Skunkware 98.iso / src / mail / pine3.96.tar.gz / pine3.96.tar / pine3.96 / pine / osdep / fltrname.dos < prev    next >
Text File  |  1995-12-11  |  4KB  |  134 lines

  1. /*----------------------------------------------------------------------
  2.     Filter file names for strange characters
  3.  
  4.    Args:  file  -- the file name to check
  5.  
  6.  Result: Returns NULL if file name is OK
  7.          Returns formatted error message if it is not
  8.   ----*/
  9. char *
  10. filter_filename(file)
  11.     char *file;
  12. {
  13. #ifdef ALLOW_WEIRD
  14.     static char illegal[] = {'\177', '\0'};
  15. #else
  16.     static char illegal[] = {'"', '#', '$', '%', '&', /*'/',*/ '(', ')','*',
  17.                           ',', ';', '<', '=', '>', '?', '[', ']',
  18.                           '^', '|', '\177', '\0'};
  19. #endif
  20.     static char error[100];
  21.     char ill_file[MAXPATH+1], *ill_char, *ptr, e2[10];
  22.     int  i;
  23.  
  24.     for(ptr = file; *ptr == ' '; ptr++) ; /* leading spaces gone */
  25.  
  26.     while(*ptr && *ptr > ' ' && strindex(illegal, *ptr) == 0)
  27.       ptr++;
  28.  
  29.     if(*ptr != '\0') {
  30.         if(*ptr == ' ') {
  31.             ill_char = "<space>";
  32.         } else if(*ptr == '\n') {
  33.             ill_char = "<newline>";
  34.         } else if(*ptr == '\r') {
  35.             ill_char = "<carriage return>";
  36.         } else if(*ptr == '\t') {
  37.             ill_char = "<tab>";
  38.         } else if(*ptr < ' ') {
  39.             sprintf(e2, "control-%c", *ptr + '@');
  40.             ill_char = e2;
  41.         } else if (*ptr == '\177') {
  42.             ill_char = "<del>";
  43.         } else {
  44.             e2[0] = *ptr;
  45.             e2[1] = '\0';
  46.             ill_char = e2;
  47.         }
  48.         if(ptr != file) {
  49.             strncpy(ill_file, file, ptr - file);
  50.             ill_file[ptr - file] = '\0';
  51.             sprintf(error,
  52.             "Character \"%s\" after \"%s\" not allowed in file name",
  53.             ill_char, ill_file);
  54.         } else {
  55.             sprintf(error,
  56.                     "First character, \"%s\", not allowed in file name",
  57.                     ill_char);
  58.         }
  59.             
  60.         return(error);
  61.     }
  62.  
  63.     if((i=is_writable_dir(file)) == 0 || i == 1){
  64.     sprintf(error, "\"%s\" is a directory", file);
  65.         return(error);
  66.     }
  67.  
  68.     if(ps_global->restricted || ps_global->VAR_OPER_DIR){
  69.     for(ptr = file; *ptr == ' '; ptr++) ;    /* leading spaces gone */
  70.  
  71.     if((ptr[0] == '.' && ptr[1] == '.') || srchstr(ptr, "/../")){
  72.         sprintf(error, "\"..\" not allowed in filename");
  73.         return(error);
  74.     }
  75.     }
  76.  
  77.     return(NULL);
  78. }
  79.  
  80.  
  81. /*----------------------------------------------------------------------
  82.     Check to see if user is allowed to read or write this folder.
  83.  
  84.    Args:  s  -- the name to check
  85.  
  86.  Result: Returns 1 if OK
  87.          Returns 0 and posts an error message if access is denied
  88.   ----*/
  89. int
  90. cntxt_allowed(s)
  91.     char *s;
  92. {
  93.     struct variable *vars = ps_global->vars;
  94.     int retval = 1;
  95.     MAILSTREAM stream; /* fake stream for error message in mm_notify */
  96.  
  97.     if(ps_global->restricted
  98.          && (strindex("./~", s[0]) || srchstr(s, "\\..\\"))){
  99.     stream.mailbox = s;
  100.     mm_notify(&stream, "Restricted mode doesn't allow operation", WARN);
  101.     retval = 0;
  102.     }
  103.     else if(VAR_OPER_DIR
  104.         && s[0] != '{' && !(s[0] == '*' && s[1] == '{')
  105.         && strucmp(s,ps_global->inbox_name) != 0
  106.         && strcmp(s, ps_global->VAR_INBOX_PATH) != 0){
  107.     char *p, *free_this = NULL;
  108.  
  109.     p = s;
  110.     /* add home dir to relative paths */
  111.     if(s[0] != '/'){
  112.         free_this = p = (char *)fs_get(strlen(s)
  113.                         + strlen(ps_global->home_dir) + 2);
  114.         build_path(p, ps_global->home_dir, s);
  115.     }
  116.     
  117.     if(!in_dir(VAR_OPER_DIR, p)){
  118.         char err[200];
  119.  
  120.         sprintf(err, "No operations allowed outside of %s", VAR_OPER_DIR);
  121.         stream.mailbox = p;
  122.         mm_notify(&stream, err, WARN);
  123.         retval = 0;
  124.     }
  125.  
  126.     if(free_this)
  127.       fs_give((void **)&free_this);
  128.     }
  129.     
  130.     return retval;
  131. }
  132.  
  133.  
  134.